//
// Created by Administrator on 2024/11/18.
//

#include "DateUtils.h"


std::string DateUtils::getCurrentTimeString(const std::string &format) {
    auto local_time = DateUtils::getCurrentLocalTime();

    std::ostringstream oss;
    oss << std::put_time(local_time, format.c_str());
    return oss.str();
}


std::string DateUtils::getCurrentDateString() {
    return getCurrentTimeString("%Y-%m-%d");
}


std::string DateUtils::getCurrentTimeOnlyString() {
    return getCurrentTimeString("%H:%M:%S");
}


std::time_t DateUtils::getCurrentTimeStamp() {
    return std::time(nullptr);
}

int DateUtils::getCurrentYear() {
    auto local_time = DateUtils::getCurrentLocalTime();
    return (1900 + local_time->tm_year);
}

int DateUtils::getCurrentMonth() {
    auto local_time = DateUtils::getCurrentLocalTime();
    return (1 + local_time->tm_mon);
}

int DateUtils::getCurrentDay() {
    auto local_time = DateUtils::getCurrentLocalTime();
    return local_time->tm_mday;
}

std::tm *DateUtils::getCurrentLocalTime() {
    std::time_t t = DateUtils::getCurrentTimeStamp();
    return std::localtime(&t);
}
